<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * utils for kison.
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;kison/utils&quot;, function (S) {
    var doubleReg = /&quot;/g, single = /'/g, escapeString;

<span id='KISSY-Kison-Utils'>    /**
</span>     * utils for kison
     * @class KISSY.Kison.Utils
     * @singleton
     */
    return {
        escapeString: escapeString = function (str, quote) {
            var regexp = single;
            if (quote == '&quot;') {
                regexp = doubleReg;
            } else {
                quote = &quot;'&quot;;
            }
            return str.replace(/\\/g, '\\\\')
                .replace(/\r/g, '\\r')
                .replace(/\n/g, '\\n')
                .replace(/\t/g, '\\t')
                .replace(regexp, '\\' + quote);
        },

        serializeObject: function serializeObject(obj, excludeReg) {
            var r;

            if (excludeReg &amp;&amp;
                (typeof excludeReg === 'function') &amp;&amp;
                (r = excludeReg(obj)) === false) {
                return false;
            }

            if (r !== undefined) {
                obj = r;
            }

            var ret = [];

            if (typeof obj == 'string') {
                return &quot;'&quot; + escapeString(obj) + &quot;'&quot;;
            } else if (typeof obj==='number') {
                return obj + &quot;&quot;;
            } else if (S.isRegExp(obj)) {
                return '/' +
                    obj.source + '/' +
                    (obj.global ? 'g' : '') +
                    (obj.ignoreCase ? 'i' : '') +
                    (obj.multiline ? 'm' : '');
            } else if (S.isArray(obj)) {
                ret.push('[');
                var sub = [];
                S.each(obj, function (v) {
                    var t = serializeObject(v, excludeReg);
                    if (t !== false) {
                        sub.push(t);
                    }
                });
                ret.push(sub.join(', '));
                ret.push(']');
                return ret.join(&quot;&quot;);
            } else if (S.isObject(obj)) {
                ret = ['{'];
                var start = 1;
                for (var i in obj) {
                    var v = obj[i];
                    if (excludeReg &amp;&amp; S.isRegExp(excludeReg) &amp;&amp; i.match(excludeReg)) {
                        continue;
                    }
                    var t = serializeObject(v, excludeReg);
                    if (t === false) {
                        continue;
                    }
                    var key = &quot;'&quot; + escapeString(i) + &quot;'&quot;;
                    ret.push((start ? '' : ',') + key + ': ' + t);
                    start = 0;
                }
                ret.push('}');
                return ret.join('\n');
            } else {
                return obj + '';
            }
        }
    };

});</pre>
</body>
</html>
